package refactor.formtemplatemethod.original;

import java.util.List;

public class Customer {
    private List<Rental> rentals;
    private String name;

    public Customer(List rentals, String name) {
        this.rentals = rentals;
        this.name = name;
    }

    public String state() {
        String result = "Rental Record for " + getName() + "\n";
        for (Rental rental : rentals) {
            //show figures for this rental
            result += "\t" + rental.getMovie().getTitle() + "\t" +
                    rental.getCharge() + "\n";
        }
        //add footer lines
        result += "Amount owed is " + calcTotalAmount() + "\n";
        result += "You earned " + calcFrequentRenterPoints() +
                " frequent renter points";
        return result;
    }

    public String htmlState() {
        String result = "<H1>Rental Record for " + getName() + "</H1>\n";
        for (Rental rental : rentals) {
            //show figures for this rental
            result += "\t" + rental.getMovie().getTitle() + ":" +
                    rental.getCharge() + "<BR>\n";
        }
        //add footer lines
        result += "<P>Amount owed is " + calcTotalAmount() + "</P>\n";
        result += "<P>You earned " + calcFrequentRenterPoints() +
                " frequent renter points</P>";
        return result;
    }

    public double calcTotalAmount() {
        double totalAmount = 0;
        for (Rental rental : rentals) {
            totalAmount += rental.getCharge();
        }
        return totalAmount;
    }


    public int calcFrequentRenterPoints() {
        int frequentRenterPoints = 0;
        for (Rental rental : rentals) {
            frequentRenterPoints = rental.getFrequentRenterPoint();
        }
        return frequentRenterPoints;
    }

    public String getName() {
        return name;
    }

}